<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>仓库设置</title>
</head>
<body>
<div style="width:100%">

    <div class="items clearfix">
        <h2 style="" class="tal">正在操作：<!--{if $store}-->修改仓库<!--{else}-->添加仓库<!--{/if}--></h2>
        <div class="items2">

            <form id="store_form" onsubmit="return false;">
                <table style="margin-bottom: 20px;">
                    <tbody>
                    <tr>
                        <td class="tar">仓库编号：</td>
                        <td>
                            <input type="text" maxlength="20" id="storeNo" name="storeNo" style="width:250px;ime-mode:active" value="<!--{if $store->storeNo}--> <!--{$store->storeNo}--> <!--{else}--> <!--{$store_no}--> <!--{/if}-->" />
                            <font color="red">*</font>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">仓库名称：</td>
                        <td>
                            <input type="text" maxlength="20" id="storeName" name="storeName" style="width:250px;" value="<!--{$store->storeName}-->" />
                            <font color="red">*</font>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">优先级：</td>
                        <td>
                            <input type="text" maxlength="20" id="priority" name="priority" style="width:250px;" value="<!--{$store->priority}-->" />
                            <font color="red">*</font>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">联系人：</td>
                        <td>
                            <input type="text" maxlength="20" id="linkman" name="linkman" style="width:250px;" value="<!--{$store->linkman}-->" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">所在地区：</td>
                        <td>
                            <select name="provinceID" id="provinceID" style="width: 110px;">
                                <option value="">请选择</option>
                                <!--{foreach from=$provinceList item=province}-->
                                    <option value="<!--{$province->id}-->" <!--{if $store->provinceID == $province->id}--> selected <!--{/if}--> ><!--{$province->name}--></option>
                                <!--{/foreach}-->
                            </select>

                            <select name="cityID" id="cityID" style="width: 110px;">

                                <option value="">请选择</option>
                                <!--{foreach from=$cityList item=city}-->
                                    <option value="<!--{$city->id}-->" <!--{if $store->cityID == $city->id}--> selected <!--{/if}--> ><!--{$city->name}--></option>
                                <!--{/foreach}-->

                            </select>

                            <select name="regionID" id="regionID" style="width: 110px;">
                                <option value="">请选择</option>
                                <!--{foreach from=$regionList item=region}-->
                                    <option value="<!--{$region->id}-->" <!--{if $store->regionID == $region->id}--> selected <!--{/if}--> ><!--{$region->name}--></option>
                                <!--{/foreach}-->
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">街道地址：</td>
                        <td>
                            <textarea id="address" name="address" style="width:97%;height: 100px;" ><!--{$store->address}--></textarea>
                            <font color="red">*</font>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">邮编：</td>
                        <td>
                            <input type="text" maxlength="20" id="postCode" name="postCode" style="width:250px;" value="<!--{$store->postCode}-->" />
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">电话号码：</td>
                        <td>
                            <input type="text" maxlength="3" id="p1" name="p1" style="width:80px;" value="<!--{$store->p1}-->" />
                            -
                            <input type="text" maxlength="8" id="p2" name="p2" style="width:100px;" value="<!--{$store->p2}-->" />
                            -
                            <input type="text" maxlength="6" id="p3" name="p3" style="width:80px;" value="<!--{$store->p3}-->" />

                            <font color="red">(区号-电话-分机号码)</font>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">手机：</td>
                        <td>
                            <input type="text" maxlength="20" id="mobile" name="mobile" style="width:250px;" value="<!--{$store->mobile}-->" />
                            <font color="red">(手机和号码至少填一项)</font>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">仓库说明：</td>
                        <td>
                           <textarea id="description" name="description" style="width:97%;height:100px"><!--{$store->description}--></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td class="tar">设为默认：</td>
                        <td>
                            <!--{if $store}-->

                                <input type="checkbox" name="isdefault" id="isdefault" value="1" <!--{if $store->isdefault == 1}-->checked<!--{/if}--> >

                            <!--{else}-->

                                <input type="checkbox" name="isdefault" id="isdefault" value="1">

                            <!--{/if}-->

                        </td>
                    </tr>
                    <input type="hidden" name="storeID" value="<!--{$store->storeID}-->">
                    </tbody>
                </table>
            </form>

        </div>
    </div>

    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="storeAdd.check();" value="<!--{if $store}-->修改仓库<!--{else}-->添加仓库<!--{/if}-->" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>



</div>

<script type="text/javascript">

    //全局变量
    var storeID = '<!--{$store->storeID}-->';

    //变更省份
    $("#provinceID").change(function(k,v){

        //区选择框置空
        $("#regionID").html('<option value="">请选择</option>');

        var pID = $(this).val();

        if( pID == '' ){
            $("#cityID").html('<option value="">请选择</option>');
            return false;
        }

        jquery_ajax(5,{id:pID,flg:1} , storeAdd.getCityList );

    });

    //变更城市
    $("#cityID").change(function(k,v){

        var cID = $(this).val();

        if( cID == '' ){

            $("#regionID").html('<option value="">请选择</option>');

            return false;
        }

        jquery_ajax(5,{id:cID,flg:2} , storeAdd.getRegionList );

    });

    var storeAdd = {

        dt: "",

        check: function() {

            this.dt = E.getFormValues('store_form');
            var error_msg = "";

            var isdefault = document.getElementById('isdefault').checked;

            if( isdefault == true ){
                defaultValue = 1;
            }else{
                defaultValue = 0;
            }

            this.dt['default'] = defaultValue;

            if ( this.dt.storeNo == "")
                error_msg += "仓库编号不能为空<br>";

            if ( this.dt.storeName == "")
                error_msg += "仓库名称不能为空<br>";

            if ( this.dt.priority == ""){
                error_msg += "仓库优先级不能为空<br>";
            }else{

                if( !E.isInt(this.dt.priority) )
                    error_msg += "优先级格式有误<br>";

            }

            if( this.dt.provinceID == '' || this.dt.cityID == '' || this.dt.regionID == '' )
                error_msg += "省市区都不能为空<br>";

            if( this.dt.address == '' )
                error_msg += "街道地址不能为空<br>";

            var phone = '';

            if( this.dt.p1 != '' ){
                phone += this.dt.p1;
            }

            if( this.dt.p2 != '' ){

                if( phone == '' ){
                    phone += this.dt.p2;
                } else {
                    phone += '-' + this.dt.p2;
                }

            }

            if( this.dt.p3 != '' ){

                if( phone == '' ){
                    phone += this.dt.p3;
                } else {
                    phone += '-' + this.dt.p3;
                }

            }

            this.dt['phone'] = phone;

            if( phone != '' && !E.isPhone(phone) ){
                error_msg += "电话号码格式有误<br>";
            }

            if( this.dt.mobile != '' &&  !E.isMobile( this.dt.mobile )){
                error_msg += "手机号码格式有误<br>";
            }

            if( phone == '' && this.dt.mobile == ''){
                error_msg += "手机和电话至少填写一项<br>";
            }

            if (error_msg != ""){
                E.alert(error_msg);
                return false;
            }

            this.add();

        },

        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/wms/store.ajax?operFlg=2",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {

                        E.opener("store.load");

                        if( storeID ){
                            E.alert(result_obj.message , 2 , "E.closeWindows()");
                        }else{
                            E.alert(result_obj.message , 2 , "storeAdd.clear");
                        }


                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //获取城市信息
        getCityList:function( obj ){

            if($.isEmptyObject( obj.data ) ){
                $("#cityID").html('<option value="">请选择</option>');
                $("#regionID").html('<option value="">请选择</option>');
                return false;
            }

            //连接HTML字符串
            var htmlString = '<option value="">请选择</option>';

            for( var i=0; i<obj.data.length; i++ ){

                htmlString += '<option value="'+obj.data[i].id+'">'+obj.data[i].name+'</option>';

            }

            $("#cityID").html(htmlString);

        },

        //获取区域信息
        getRegionList:function( obj ){

            if($.isEmptyObject( obj.data ) ){
                $("#regionID").html('<option value="">请选择</option>');
                return false;
            }

            //连接HTML字符串
            var htmlString = '<option value="">请选择</option>';

            for( var i=0; i<obj.data.length; i++ ){

                htmlString += '<option value="'+obj.data[i].id+'">'+obj.data[i].name+'</option>';

            }

            $("#regionID").html(htmlString);

        },

        clear:function(){
            self.location= '/quanliadmin/app/wms/store.pscript?operFlg=2';
        }

    };

    function jquery_ajax(flg,data,func){
        $.ajax({
            type: "post",
            url: "/invokingAjax-backend/wms/store.ajax?operFlg="+flg,
            dataType: "json",
            data: data,
            success: function( result_obj ) {
                func(result_obj);
            },
            error : function(msg){
                E.alert('网络不给力，请重新尝试...',1);
            }
        });
    }

</script>

</body>

</html>
